#include "AddScorePlayerNetworkEvent.h"
#include "Score.h"
#include <cstring>

AddScorePlayerNetworkEvent::AddScorePlayerNetworkEvent(long textId, const std::string& playerName, const Color& color)
{
    message.header.code = NetworkEvent::SERVER_ADD_SCORE_PLAYER;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.textId = textId;
    strncpy(message.data.playerName, playerName.c_str(), sizeof(message.data.playerName));
    message.data.r = color.r;
    message.data.g = color.g;
    message.data.b = color.b;
}

AddScorePlayerNetworkEvent::AddScorePlayerNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

AddScorePlayerNetworkEvent::~AddScorePlayerNetworkEvent()
{
}

void* AddScorePlayerNetworkEvent::getMessageBlob()
{
    return &message;
}

size_t AddScorePlayerNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}

void AddScorePlayerNetworkEvent::visitScore(Score* score) const
{
    score->addPlayer(message.data.textId, message.data.playerName, Color(message.data.r, message.data.g, message.data.b));
}

